package com.chang.rentmall.servicesImpl;

import com.chang.rentmall.beans.UserBean;
import com.chang.rentmall.daos.UserDao;
import com.chang.rentmall.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service("UserService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public HashMap<String, Object> getUserList(UserBean userBean) {
        List<UserBean> userList = userDao.getUserList();
        HashMap<String, Object> result = new HashMap<String, Object>();
        result.put("statusCode", 200);
        result.put("message", "查询数据成功！");
        result.put("list", userList);
        return result;
    }

    @Override
    public HashMap<String, Object> addUser(UserBean userBean) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String d = df.format(new Date());
        userBean.setCreateTime(d);
        userBean.setUpdateTime(d);
        int flag = userDao.addUser(userBean);
        if (flag == 1) {
            result.put("message", "操作成功");
            result.put("statusCode", 200);
        } else {
            result.put("message", "操作失败");
            result.put("statusCode", -1);
        }
        return result;
    }

    @Override
    public HashMap<String, Object> updateUser(UserBean userBean) {
        return null;
    }

    @Override
    public HashMap<String, Object> getUserById(int id) {
        return null;
    }
}
